package com.onlineMIS.ORM.entity.headQ.finance;


import java.io.IOException;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;

import com.onlineMIS.ORM.entity.chainS.report.ChainSalesReport;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.Color;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.Product;
import com.onlineMIS.ORM.entity.headQ.inventory.InventoryOrder;
import com.onlineMIS.ORM.entity.headQ.inventory.InventoryOrderProduct;
import com.onlineMIS.common.Common_util;
import com.onlineMIS.common.ExcelTemplate;
import com.onlineMIS.common.loggerLocal;

import antlr.StringUtils;
import freemarker.template.utility.StringUtil;


public class FinanceBillReportTemplate extends ExcelTemplate{

	private final int date_row_ind = 1;
	private final int data_row_ind = 5;
	
	private final int chain_column = 0;
	private final int sales_q_column= 1;

	
	private List<FinanceBillVO> rptEles = new ArrayList<FinanceBillVO>();
	private Date startDate;
	private Date endDate;
//	private String path;
	private String chainName;

	public FinanceBillReportTemplate(Date startDate, Date endDate,String chainName, String templateWorkbookPath, List<FinanceBillVO> rptEles) throws IOException{
		super(templateWorkbookPath);		
		this.startDate = startDate;
		this.endDate = endDate;
		this.chainName = chainName;
		this.rptEles = rptEles;

	}
	
	public HSSFWorkbook process() {
		HSSFSheet sheet = templateWorkbook.getSheetAt(0);

		// 写报表头信息
		String startDate = Common_util.dateFormat.format(this.startDate);
		String endDate = Common_util.dateFormat.format(this.endDate);

		Row headerRow2 = sheet.getRow(1);
		loggerLocal.info(this.chainName + "店铺名称");
		if (this.chainName == null || this.chainName.length() == 0) {
			this.chainName = "所有连锁店";
		}

		headerRow2.createCell(1).setCellValue(this.chainName);

		Row headerRow3 = sheet.getRow(2);
		headerRow3.createCell(1).setCellValue(startDate);

		Row headerRow4 = sheet.getRow(3);
		headerRow4.createCell(1).setCellValue(endDate);

		//

		for (int i = 0; i < rptEles.size(); i++) {
			FinanceBillVO saleReport = rptEles.get(i);
			Row row = sheet.createRow(i + data_row_ind);
			row.createCell(chain_column).setCellValue(saleReport.getCustName());
			row.createCell(sales_q_column).setCellValue(saleReport.getBillId());
			row.createCell(2).setCellValue(saleReport.getBillTypeS()); // 单据种类
			row.createCell(3).setCellValue(saleReport.getDate().toString()); // 单据日期
			row.createCell(4).setCellValue(saleReport.getAmount()); // 金额
			row.createCell(5).setCellValue(saleReport.getStatusS()); // 状态
			row.createCell(6).setCellValue(saleReport.getRemark());
		}
		return templateWorkbook;
	}

}
